"""
# 对数变换
"""
import pandas as pd
import numpy as np
import json
import matplotlib.pyplot as plt

biz_file = open('../数据集/yelp_academic_dataset_business.json')
biz_df = pd.DataFrame([json.loads(x) for x in biz_file.readlines()])
fig, (ax_orig, ax_log) = plt.subplots(2, 1)
biz_df['review_count'].hist(ax=ax_orig, bins=100)
ax_orig.tick_params(labelsize=14)
ax_orig.set_xlabel('Review Count', fontsize=14)
ax_orig.set_ylabel('Occurrence', fontsize=14)

biz_df['log_review_count'] = np.log10(biz_df['review_count'] + 1)
biz_df['log_review_count'].hist(ax=ax_log, bins=100)
ax_log.tick_params(labelsize=14)
ax_log.set_xlabel('Log10(Review Count)', fontsize=14)
ax_log.set_ylabel('Occurrence', fontsize=14)

plt.show()

news_df = pd.read_csv('../数据集/OnlineNewsPopularity.csv', delimiter=',', header=0)
fig, (ax_orig, ax_log) = plt.subplots(2, 1)
news_df[' n_tokens_content'].hist(ax=ax_orig, bins=100)
ax_orig.tick_params(labelsize=14)
ax_orig.set_xlabel('Number of Words in Article', fontsize=14)
ax_orig.set_ylabel('Number of Article', fontsize=14)

news_df['log_n_tokens_content'] = np.log10(news_df[' n_tokens_content'] + 1)
news_df['log_n_tokens_content'].hist(ax=ax_log, bins=100)
ax_log.tick_params(labelsize=14)
ax_log.set_xlabel('Log of Number of Words in Article', fontsize=14)
ax_log.set_ylabel('Number of Article', fontsize=14)
plt.savefig('./可视化/新闻文章流行度分布可视化_使用对数变换和不使用对数变换.png')
plt.show()
